package com.player;

import java.util.List;

import com.execaction.CmdTaskQueue;
import com.mgr.DriverOrderMgr;
import com.qy.DaoMgr;
import com.qy.bean.DriverInfo;
import com.qy.bean.Option;
import com.qy.bean.OrderDriver;
import com.qy.util.StaticData;
import com.qy.util.TimeUtil;

/**
 * 司機用戶
 * 1.保存司機信息
 * 2.保存通道信息
 * 
 * @author zwl
 * 
 */
public class DriverUser extends User{
	
	//司机的信息
	private DriverInfo driverInfo;
	//正在服务的id
	private OrderDriver serverOrder = null;

	public DriverUser() {
		super();
	}
	
	public DriverUser(CmdTaskQueue cmdTaskQueue) {
		super(cmdTaskQueue);
	}

	
	public boolean loadData(DriverInfo driverInfo) {
		this.driverInfo = driverInfo;
		List<OrderDriver> list =
			DriverOrderMgr.getDriverOrder(driverInfo.getId(),
				StaticData.DriverOrderStatus.START.getType());
		if(list!=null&&list.size()>0){
		    serverOrder = list.get(0);
		}
		return true;
	}
	
	public DriverInfo getDriverInfo() {
		return driverInfo;
	}

	public void setDriverInfo(DriverInfo driverInfo) {
		this.driverInfo = driverInfo;
	}
	
	
	public DriverInfo createUserInfo(String openid){
		DriverInfo userInfo = new DriverInfo();
		userInfo.setThirdId(openid);
		userInfo.setCreateDate(TimeUtil.getSysteCurTime());
		userInfo.setUserType(StaticData.userType.DRIVER_USER.getType());
		userInfo.setUserStatus(StaticData.driverStatus.perfect_information.getType());
		userInfo.setOp(Option.Insert);
		DaoMgr.getDriverInfoDao().createDriverInfo(userInfo);
		return userInfo;
	}

	@Override
	public void save() {
		DaoMgr.getDriverInfoDao().updateDriverInfo(driverInfo);
	}

	@Override
	public int getUserStatus() {
		return this.driverInfo.getUserStatus();
	}

	@Override
	public int getID() {
		return this.driverInfo.getId();
	}

	@Override
	public String getKey() {
		return this.driverInfo.getId()+StaticData.first_split+StaticData.userType.DRIVER_USER.getType();
	}

	@Override
	public int getUserType() {
		return this.driverInfo.getUserType();
	}
	/**
	 * 获取正在服务的id
	 * @return
	 */
	public OrderDriver getServerOrder() {
	    return serverOrder;
	}

	public void setServerOrder(OrderDriver serverOrder) {
	    this.serverOrder = serverOrder;
	}

	@Override
	public String getOpenId() {
	    return this.driverInfo.getThirdId();
	}
	

	

}
